package com.ssm.admin.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssm.admin.entity.dto.SaleOrderDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ssm.admin.entity.SsmSalesorderEntity;
import com.ssm.admin.service.SsmSalesorderService;
import com.ssm.common.utils.PageUtils;
import com.ssm.common.utils.R;



/**
 * 
 *
 * @author ssm
 * @email sunlightcs@gmail.com
 * @date 2023-03-19 17:30:08
 */
@RestController
@RequestMapping("admin/ssmsalesorder")
public class SsmSalesorderController {
    @Autowired
    private SsmSalesorderService ssmSalesorderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        //获取param中的page
        Integer currentPage = Integer.parseInt(params.get("page").toString());
        //获取param中的limit
        Integer limit = Integer.parseInt(params.get("limit").toString());
        //获取param中的key
        String key= (String) params.get("key").toString().trim();
        Integer count = ssmSalesorderService.findCount();
        //判断key是否为空
        if (StringUtils.isEmpty(key)){
            List<SaleOrderDto> orderDtoList = ssmSalesorderService.findOrderByUsername(key, (currentPage-1)*limit, limit);

        }
        List<SaleOrderDto> orderDtoList = ssmSalesorderService.findOrderByUsername(key,(currentPage-1)*limit, limit);
        PageUtils page = new PageUtils(orderDtoList,count,limit,currentPage);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{soId}")
    public R info(@PathVariable("soId") String soId){
		SsmSalesorderEntity ssmSalesorder = ssmSalesorderService.getById(soId);

        return R.ok().put("ssmSalesorder", ssmSalesorder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SsmSalesorderEntity ssmSalesorder){
		ssmSalesorderService.save(ssmSalesorder);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SsmSalesorderEntity ssmSalesorder){
		ssmSalesorderService.updateById(ssmSalesorder);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] soIds){
		ssmSalesorderService.removeByIds(Arrays.asList(soIds));

        return R.ok();
    }

}
